home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
mcomm557.zip
/
COMM.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-11
|
18KB
|
382 lines
/////////////////////////////////////////////////////////////////////////////
// //
// COMM.HPP -- header file for C++ programs using MCOMM async routines. //
// Zortech C++ 2.0, Turbo C++ 1.00 version. //
// //
// Mike Dumdei, 6 Holly Lane, Texarkana TX 75503 (c) 1989,1990 //
// //
/////////////////////////////////////////////////////////////////////////////
#if !defined(COMM_HPP)
#define COMM_HPP
#ifndef MCOMM
#define _C_ cdecl
#define _V_ volatile
#define _F_ far
#if (__TURBOC__ && __HUGE__)
#define _N_
#else
#define _N_ near
#endif
#define MCOMM
#endif
//////////////////////////////////////////////
// Return codes //
//////////////////////////////////////////////
#ifndef __ZTC__
#define R_OK 0x0000
#endif
#define R_NOMEM 0x0001
#define R_BAUDERR 0x0002
#define R_PARITYERR 0x0004
#define R_DTABITERR 0x0008
#define R_STPBITERR 0x0010
#define R_IRQUSED 0x0020
#define R_VCTRUSED 0x0040
#define R_NOPORT 0x0080
#define R_PORTUSED 0x0100
#define R_UARTERR 0x0200
#define R_TXERR (-1)
//////////////////////////////////////////////
// Interrupt bit masks //
//////////////////////////////////////////////
#define IRQ3 0x08
#define IRQ4 0x10
//////////////////////////////////////////////
// Vector numbers //
//////////////////////////////////////////////
#define VCTR3 0x0b
#define VCTR4 0x0c
//////////////////////////////////////////////
// Standard Comm Ports //
// Note - due to the ability to overload //
// the open call, COM1 and COM2 are def- //
// ined differently in the C++ version. //
//////////////////////////////////////////////
#define COM1 0
#define COM2 1
//////////////////////////////////////////////
// Defines for async_regs function //
//////////////////////////////////////////////
#define RXreg 0
#define TXreg 0
#define IERreg 1
#define IIDreg 2
#define FCRreg 2
#define LCRreg 3
#define MCRreg 4
#define LSRreg 5
#define MSRreg 6
#define LObaud 0
#define HIbaud 1
//////////////////////////////////////////////
// Miscellaneous bit masks //
//////////////////////////////////////////////
#define B_DTR 0x0001
#define B_RTS 0x0002
/////////////////////////////////////////////////////////////////////////
// Status bit masks //
/////////////////////////////////////////////////////////////////////////
// S T A T 2 //
#define B_XUSE 0x0001 // using XON/XOFF protocol bit
#define B_XRXD 0x0002 // XOFF received bit
#define B_XSENT 0x0004 // XOFF sent bit
#define B_TXEMPTY 0x0008 // nothing to transmit bit
#define B_CTS 0x0010 // clear to send bit
#define B_DSR 0x0020 // data set ready bit
#define B_FLOWHALT 0x0040 // flow halt indicator bit
#define B_MNTR_CD 0x0080 // monitor CD bit
// S T A T 1 //
#define B_RXOVF 0x0100 // rx buffer overflow indic bit
#define B_OVERRUN 0x0200 // char overrun error bit
#define B_PARITY 0x0400 // parity error bit
#define B_FRAMING 0x0800 // framing error bit
#define B_BREAK 0x1000 // line break signal detected
#define B_THRE 0x2000 // used in interrupt hdlr (always 0)
#define B_RXEMPTY 0x4000 // rx buffer empty bit
#define B_CD 0x8000 // carrier detect bit mask
// S T A T 3 //
#define B_IGNERR 0x0001 // discard chars with par, frm'g errs
#define B_16550 0x0002 // 16550 detected
#define B_FIFO 0x0004 // 16550 FIFOs enabled
#define B_ORGFIFO 0x0008 // FIFOs were on when port was opened
#define B_FARBUFFER 0x0010 // using FAR ring buffers
#define B_XUSET 0x0020 // using XON/XOFF on txmt side bit
#define B_XUSER 0x0040 // using XON/XOFF on recv side bit
#define B_XONANY 0x0080 // accept any char for an XON
/////////////////////////////////////////////////////////////////////////
// //
// A s y n c P o r t C l a s s //
// //
// * * * W A R N I N G * * * //
// This class must have the port variables byte aligned. As //
// written, ZTC 2.0 will byte align this structure without the //
// need to direct it to pack structures. If you are using //
// a different implementation of C++ be sure this data is //
// byte aligned by your compiler. //
/////////////////////////////////////////////////////////////////////////
class AsyncPort
{
// port variables
private:
int ComBase; // base port address of for comm port
char IRQMask; // mask for IRQ used by this port
char Vector; // interrupt vector used by this port
char BPDSstr[10]; // current baud,parity,data,stop parms
int RxSize; // size of receive bufr
int TxSize; // size of transmit bufr
int RingSeg; // segment of rx/tx bufrs (leave 0 for NEAR)
int RingOfst; // offset of rx/tx bufrs, alias TxTop
int RxTop; // ptr to begin of rx bufr, alias TxBtm
int RxBtm; // ptr to end of rx bufr (end + 1)
int _V_ TxIn; // ptr to where next 'put' goes
int _V_ TxOut; // ptr to where next tx'd comes from
int _V_ TxFree; // remaining tx bufr space
int _V_ RxIn; // pointer to where next rx'd goes
int _V_ RxOut; // ptr to where next 'get' comes from
int _V_ RxFree; // remaining bytes in rx bufr space
int BaudDvsr; // baud rate divisor
int XoffTrip; // send XOFF when this many bytes left in rxbuf
int XonTrip; // send XON when this many bytes left in rxbuf
int OldVctrOfst; // OFST address of original interrupt vector
int OldVctrSeg; // SEG address of original interrupt vector
int OldDvsr; // original value of Baud Divisor Regs
char _V_ Stat2; // secondary status byte
char _V_ Stat1; // primary status byte
char _V_ TxStat; // determines when tx_intrpts need turned on
char MSRMask; // slcts bits in MSR montrd for flow cntrl
char _V_ MSRVal; // present value of modem status register
char _V_ Stat3; // another flag, used for XONANY char
char PDSinfo; // parity, # dta bits, # stop bits
char StripMask; // mask for high bit stripping
char XTxRptInit; // initialization value for XTxRpt below
char _V_ XTxRpt; // countdown val befr repeat tx of XOFF
char _V_ TxImmedChar; // char to be tx'd 1st opportunity
char HdlrUsed; // assigned interrupt handler for this port
char Old8259Msk; // original 8259 interrupt mask
char OldLCR; // original Line Control Reg value
char OldMCR; // original Modem Cntrl Reg value
char OldIER; // original Interrupt Enable Reg value
int TxByteCnt; // number bytes to send per tx interrupt
char FCRVal; // FIFO control register data byte
char IERVal; // interrupt enable register value
char _V_ MCRVal; // modem